﻿using NewHPDNWcfService.DAO;
using NewHPDNWcfService.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace NewHPDNWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }


        public User GetUserById(int id)
        {
            return new User();
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }





        // My service methods
        public List<Table> GetAllTables()
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.getAllTables();
        }

        public void TestInsert() {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.TestInsertDate();
        }


        public Bill GetTableCurrentBill(Table table) 
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();

            return helper.GetTableCurrentBill(table);
        }

        public List<BillDetails> GetBillDetails(Bill bill)
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.GetBillDetails( bill);
        }

        public  void TablePay(Table table)
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.TablePay(table);
        }

        public void UpdateBill(Bill bill)
        { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.UpdateBill(bill);
        }


        // Thêm món cho 1 bàn nào đó
        /*
         * Table: bàn cần gọi thêm
         * Item: món ăn khách muốn gọi thêm
         * mCount: số lượng gọi thêm
         * 
         * */
        public void MoreDish(Table table, Item item, int mCount)
        { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.MoreDish(table, item, mCount);
        }


        public void UpdateBillDetail(BillDetails detail) 
        { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.UpdateBillDetail(detail);
        }

        public List<Category> GetAllCategories()
        { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.GetAllCategories();
        }

        public List<BillDetails> GetWaiting(Table table)
        { 
             DBHelper helper = DBHelperFactory.getDBHelperInstance();
             return helper.GetWaiting(table);
        }

        public List<BillDetails> GetDone(Table table)
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.GetDone(table);
        }

        public List<Item> GetItemsByCategory(Category c)
        { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.GetItemsByCategory(c);
        }

        public void GoiMon(Table table, Item item, int count)
        {
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            helper.GoiMon(table, item, count);
        }


        public Item GetItemById(int itemId) { 
            DBHelper helper = DBHelperFactory.getDBHelperInstance();
            return helper.GetItemById(itemId);
        }
    }
}
